package noahzu.github.io.baselib.utils.fragmentMaker;

import android.app.Activity;
import android.support.v4.app.Fragment;

import java.lang.ref.WeakReference;

/**
 * 提供Fragment中转功能
 *
 * Created by gejinpeng on 2017/9/28.
 */

public final class FragmentMaker {
    private final WeakReference<Activity> mContext;
    private final WeakReference<Fragment> mFragment;

    private FragmentMaker(Activity activity) {
        this(activity, null);
    }

    private FragmentMaker(Fragment fragment) {
        this(fragment.getActivity(), fragment);
    }

    private FragmentMaker(Activity activity, Fragment fragment) {
        this.mContext = new WeakReference<>(activity);
        this.mFragment = new WeakReference<>(fragment);
    }

    public static FragmentMaker from(Activity activity) {
        return new FragmentMaker(activity);
    }

    public static FragmentMaker from(Fragment fragment) {
        return new FragmentMaker(fragment);
    }

    public FragmentSpecCreator make() {
        return new FragmentSpecCreator(this);
    }

    public Activity getActivity() {
        return mContext.get();
    }

    public Fragment getFragment() {
        return mFragment.get();
    }
}
